jQuery 1.3 with PHP
By Kae Verens
()
About this ebook
To make PHP applications that respond quickly, avoid unnecessary page reloads, and provide great user interfaces, often requires complex JavaScript techniques and even then, if you get that far, they might not even work across different browsers! With jQuery, you can use one of the most popular JavaScript libraries, forget about cross-browser issues, and simplify the creation of very powerful and responsive interfaces - all with the minimum of code.
This is the first book in the market that will ease the server-side PHP coder into the client-side world of the popular jQuery JavaScript library.
This book will show you how to use jQuery to enhance your PHP applications, with many examples using jQuery's user interface library jQuery UI, and other examples using popular jQuery plugins. It will help you to add exciting user interface features to liven up your PHP applications without having to become a master of client-side JavaScript.
This book will teach you how to use jQuery to create some really stunning effects, but without you needing to have in-depth knowledge of how jQuery works. It provides you with everything you need to build practical user interfaces for everything from graphics manipulation to drag-and-drop to data searching, and much more. The book also provides practical demonstrations of PHP and jQuery and explains those examples, rather than starting from how JavaScript works and how it is different from PHP.
By the end of this book, you should be able to take any PHP application you have written, and transform it into a responsive, user-friendly interface, with capabilities you would not have dreamed of being able to achieve, all in just a few lines of JavaScript.
A practical guide for building responsive user interfaces for your web site's PHP applications, using jQuery, jQuery UI, and jQuery plugins
ApproachThis book takes a practical approach to integrating PHP and jQuery, showing examples of every point discussed. All examples are written such that you should be able to copy out the code into your own projects and see immediate results, no matter what your experience with JavaScript. You will find projects developed within a chapter, building them up step-by-step, describing the process and thought that goes into it. Minimal requirements are needed on the server-side, so the examples should work with any setup.
Who this book is forThis book is for PHP application developers who want to improve their user interfaces through jQuery's capabilities and responsiveness. Whether you are familiar with jQuery or have only dabbled a little with JavaScript, this book will provide you with numerous practical examples of how to improve your application.
Kae Verens
Kae Verens is an owner manager of the web-development company Webworks.ie and is currently secretary of the Irish PHP Users Group. He has been writing in JavaScript since the mid 90s, and in PHP since the late 90s. Kae is the creator of the file management system KFM, the CMS WebME (used by Webworks.ie for over 200 separate clients), and the author of the Packt book jQuery 1.3 with PHP.
Related to jQuery 1.3 with PHP
Related ebooks
AJAX Interview Questions, Answers, and Explanations: AJAX Certification Review Rating: 0 out of 5 stars0 ratingsjQuery Mobile Web Development Essentials - Third Edition Rating: 0 out of 5 stars0 ratingsBeginning DotNetNuke Skinning and Design Rating: 0 out of 5 stars0 ratingsResponsive Design High Performance Rating: 0 out of 5 stars0 ratingsPHP Team Development Rating: 3 out of 5 stars3/5Responsive Media in HTML5 Rating: 0 out of 5 stars0 ratingsJavaScript Concurrency Rating: 0 out of 5 stars0 ratingsRedmine Plugin Extension and Development Rating: 0 out of 5 stars0 ratingsAngularJS Deployment Essentials Rating: 0 out of 5 stars0 ratingsAJAX and PHP: Building Responsive Web Applications Rating: 4 out of 5 stars4/5PHPEclipse: A User Guide Rating: 3 out of 5 stars3/5ASP.NET 3.5 CMS Development Rating: 0 out of 5 stars0 ratingsBuilding a Web Application with PHP and MariaDB: A Reference Guide Rating: 0 out of 5 stars0 ratingsJavaScript Mobile Application Development Rating: 0 out of 5 stars0 ratingsFlex 3 with Java Rating: 0 out of 5 stars0 ratingsApache Solr PHP Integration Rating: 0 out of 5 stars0 ratingsNode Web Development, Second Edition Rating: 0 out of 5 stars0 ratingsLearning AngularJS Animations Rating: 4 out of 5 stars4/5jQuery Design Patterns Rating: 0 out of 5 stars0 ratingsMastering NetBeans Rating: 0 out of 5 stars0 ratingsLearning Behavior-driven Development with JavaScript Rating: 5 out of 5 stars5/5HTML5 for Flash Developers Rating: 5 out of 5 stars5/5Learning PHP 7 Rating: 4 out of 5 stars4/5JavaScript for Gurus: Use JavaScript programming features, techniques and modules to solve everyday problems Rating: 0 out of 5 stars0 ratingsLaravel 5 Essentials Rating: 0 out of 5 stars0 ratingsPHP 5 CMS Framework Development - 2nd Edition Rating: 0 out of 5 stars0 ratingsCakePHP 1.3 Application Development Cookbook Rating: 0 out of 5 stars0 ratingsPhpStorm Cookbook Rating: 0 out of 5 stars0 ratingsPHP Ajax Cookbook Rating: 2 out of 5 stars2/5jQuery Hotshot Rating: 0 out of 5 stars0 ratings
Information Technology For You
ChatGPT: The Future of Intelligent Conversation Rating: 4 out of 5 stars4/5Summary of Super-Intelligence From Nick Bostrom Rating: 5 out of 5 stars5/5How to Write Effective Emails at Work Rating: 4 out of 5 stars4/5How To Use Chatgpt: Using Chatgpt To Make Money Online Has Never Been This Simple Rating: 0 out of 5 stars0 ratingsCreating Online Courses with ChatGPT | A Step-by-Step Guide with Prompt Templates Rating: 4 out of 5 stars4/5Linux Command Line and Shell Scripting Bible Rating: 3 out of 5 stars3/5Supercommunicator: Explaining the Complicated So Anyone Can Understand Rating: 3 out of 5 stars3/5Computer Science: A Concise Introduction Rating: 4 out of 5 stars4/5CompTIA Network+ CertMike: Prepare. Practice. Pass the Test! Get Certified!: Exam N10-008 Rating: 0 out of 5 stars0 ratingsCompTIA A+ CertMike: Prepare. Practice. Pass the Test! Get Certified!: Core 1 Exam 220-1101 Rating: 0 out of 5 stars0 ratingsBeginner's Guide to Information Security Rating: 0 out of 5 stars0 ratingsThe Basics of Hacking and Penetration Testing: Ethical Hacking and Penetration Testing Made Easy Rating: 4 out of 5 stars4/5An Ultimate Guide to Kali Linux for Beginners Rating: 3 out of 5 stars3/5Data Analytics for Beginners: Introduction to Data Analytics Rating: 4 out of 5 stars4/5Practical Ethical Hacking from Scratch Rating: 5 out of 5 stars5/5Handbook of Digital Forensics and Investigation Rating: 4 out of 5 stars4/5Inkscape Beginner’s Guide Rating: 5 out of 5 stars5/5Hacking Essentials - The Beginner's Guide To Ethical Hacking And Penetration Testing Rating: 3 out of 5 stars3/5Panda3d 1.7 Game Developer's Cookbook Rating: 0 out of 5 stars0 ratingsComputer Organization and Design: The Hardware / Software Interface Rating: 4 out of 5 stars4/5Health Informatics: Practical Guide Rating: 0 out of 5 stars0 ratingsCybersecurity for Beginners : Learn the Fundamentals of Cybersecurity in an Easy, Step-by-Step Guide: 1 Rating: 0 out of 5 stars0 ratingsWindows Registry Forensics: Advanced Digital Forensic Analysis of the Windows Registry Rating: 4 out of 5 stars4/5CODING INTERVIEW: Advanced Methods to Learn and Excel in Coding Interview Rating: 0 out of 5 stars0 ratingsSharePoint Designer Tutorial: Working with SharePoint Websites Rating: 1 out of 5 stars1/5How to Find a Wolf in Siberia (or, How to Troubleshoot Almost Anything) Rating: 0 out of 5 stars0 ratingsData Governance For Dummies Rating: 0 out of 5 stars0 ratings
Reviews for jQuery 1.3 with PHP
0 ratings0 reviews
Book preview
jQuery 1.3 with PHP - Kae Verens
Table of Contents
jQuery 1.3 with PHP
Credits
About the Author
About the Reviewers
Preface
What this book covers
What you need for this book
Who this book is for
Conventions
Reader feedback
Customer support
Errata
Piracy
Questions
1. Introduction and Overview
Expected developer skills
Differences between PHP and JavaScript
What is jQuery?
Why jQuery?
How does jQuery fit in with PHP?
How to work with the examples
Projects that use PHP and jQuery
WordPress
RoundCube
KFM
Drupal
Summary
2. Quick Tricks
Dynamic select boxes
Client-side code
How it works
Server-side code
Quick deletes
Client-side code
Server-side code
Contextual help
Inline editing
Client-side code
Server-side code
Summary
3. Tabs and Accordions
Using a jQuery tab plugin
Client-side code
Server-side considerations
Using jQuery accordion plugins
Client-side code
Server-side management of accordions
Client-side code
Server-side code
Just the conversion
Now show the data with the accordions
Server-side management of tabs
Server-side code
Just the conversion
Now show the data with the tabs
Using special codes to define tabs
Client-side code
Server-side code
Loading accordion panels through Ajax
Client-side code
Server-side code
Loading tab panels through Ajax
Client-side code
Summary
4. Forms and Form Validation
Using the jQuery validation plugin
Client-side code
Setting up jQuery validation from PHP
Server-side code (setup)
Client-side code
Server-side code
Remote validation
Server-side code (setup)
Client-side code
Server-side code
Large select boxes
Client-side code
Server-side code
Auto-suggestion
Client-side code
Server-side code
Client-side code
Summary
5. File Management
Security
Choosing a directory
Client-side code
Server-side code
Creating, renaming, and deleting directories
Client-side code
Server-side code
Moving directories
Client-side code
Server-side code
File uploads
Client-side code
Server-side code
Renaming, deleting, and moving files
Client-side code
Server-side code
File downloads
Client-side code
Server-side code
Summary
6. Calendars
Displaying the calendar
Creating an event
Client-side code
Server-side code
Loading events from the server
Client-side code
Server-side code
Moving and resizing events
Client-side code
Server-side code
Editing events
Client-side code
Server-side code
Deleting events
Client-side code
Server-side code
Walk-through of the calendar so far
Recurring events
Client-side code
Server-side code
Deleting recurring events
Client-side code
Server-side code
Summary
7. Image Manipulation
Showing the list of images
Server-side code
Client-side code
Selecting an image
Client-side code
Server-side code
Preparing your PHP
Rotating
Client-side code
Server-side code
Caching or saving the image
Client-side code
Server-side code
Resizing
Client-side code
Server-side code
Cropping
Client-side code
Server side
Summary
8. Drag and Drop
Sorting simple lists
Client-side code
Server-side code
Client-side code
Sorting trees
Client-side code
Server-side code
Connecting lists
Client-side code
Server-side code
Summary
9. Data Tables
Setting up DataTables
Client-side code
Getting data from the server
Client-side code
Server-side code
Caching your database queries
Server-side code
Pagination through Ajax
Client-side code
Server-side code
Sorting by column
Filtering
Server-side code
Setting a delay on the filter
Summary
10. Optimization
Optimizing the page load
Place scripts at the bottom
Aggregate and cache your scripts
Output HTML similar to the post-jQuery code
Optimizing development and maintenance
Writing your own plugins
Un-caching your JavaScript
Optimizing jQuery
Use Google's CDN
Caching jQuery objects
Use $.load for non-visual code
JavaScript optimizations
Chaining
Speeding up selectors
Inject multiple elements at once
Using setTimeout
Use var for your variables
Summary
Index
jQuery 1.3 with PHP
Kae Verens
jQuery 1.3 with PHP
Copyright © 2009 Packt Publishing
All rights reserved. No part of this book may be reproduced, stored in a retrieval system, or transmitted in any form or by any means, without the prior written permission of the publisher, except in the case of brief quotations embedded in critical articles or reviews.
Every effort has been made in the preparation of this book to ensure the accuracy of the information presented. However, the information contained in this book is sold without warranty, either express or implied. Neither the author, Packt Publishing, nor its dealers or distributors will be held liable for any damages caused or alleged to be caused directly or indirectly by this book.
Packt Publishing has endeavored to provide trademark information about all the companies and products mentioned in this book by the appropriate use of capitals. However, Packt Publishing cannot guarantee the accuracy of this information.
First published: October 2009
Production Reference: 1211009
Published by Packt Publishing Ltd.
32 Lincoln Road
Olton
Birmingham, B27 6PA, UK.
ISBN 978-1-847196-98-9
www.packtpub.com
Cover Image by Louise Barr (<lou@frogboxdesign.co.uk>)
Credits
Author
Kae Verens
Reviewers
Akash Mehta
Ashok Modi
John K. Murphy
Acquisition Editor
Douglas Paterson
Development Editor
Darshana D. Shinde
Technical Editor
Ishita Dhabalia
Copy Editor
Sanchari Mukherjee
Editorial Team Leader
Gagandeep Singh
Project Team Leader
Lata Basantani
Project Coordinator
Srimoyee Ghoshal
Proofreader
Chris Smith
Indexer
Rekha Nair
Production Coordinator
Dolly Dasilva
Cover Work
Dolly Dasilva
About the Author
Kae Verens lives in Monaghan, Ireland with his wife Bronwyn and their two kids Jareth and Boann. He has been programming for twenty years, fifteen of which were as a professional.
Kae started writing in JavaScript in the mid nineties, and started working on the server-side languages a few years later. After writing CGI in C and Perl, Kae switched to PHP in 2000, and has worked with it since then.
Kae is currently the secretary of the Irish PHP Users' Group, http://php.ie/, is part-owner of the Irish web-development company Webworks.ie, http://webworks.ie/, and is the author of popular web-based file-manager KFM, http://kfm.verens.com/.
In his spare time, Kae plays the guitar, juggles, is learning to play the piano, and likes to occasionally dust the skateboard off and mess around on it.
I would like to thank Packt Publishing for considering me for this project; it's been a journey, and I've learned quite a lot from it. I would also like to thank Webworks.ie for hiring me way back in 2001, when I was a brash programmer, eager to show how things should be done. And finally, I'd like to thank Bronwyn and the kids for putting up with the days and hours that I've had to avoid them to concentrate on the book!
About the Reviewers
Akash Mehta is a web application developer and technical author based in Australia. His area of work covers e-learning solutions, information systems, and developer training. He regularly writes web development articles for Adobe, CNet, the APC Magazine, and other print and online publications. He is a regular speaker at IT conferences, user groups, and BarCamps. Currently, Akash provides various services like web development, technical writing, consulting, and training through his website, http://bitmeta.org/.
Hailing from an igloo somewhere up in Canada, Ashok Modi is currently a systems analyst for California Institute of the Arts (http://calarts.edu/). He was a systems (and games) programmer for zinc Roe Design (http://www.zincroe.com/), and has been working with Drupal for the last three years. Starting from Drupal 4.6, he is the author of the abuse module (and looking for co-maintainers!), and has helped many maintainers in updating their contributed modules from 4.7.x to 5.x to 6.x. He also helped organize DrupalCamp Toronto in 2007 and 2008 and recently presented multiple sessions at DrupalCamp LA in 2009. In his spare time, Ashok tries to help contributed module maintainers with features and bugs. He was a technical reviewer on another book, Drupal 6 Social Networking, also published by Packt Publishing.
I would like to thank my wife, Richa, for letting me obsess over technology and pushing me to freelance and try other open-source technologies in my spare time.
John K. Murphy is a graduate of the University of West Virginia and has been wrapped up in computers and software development since the 1980s. When he is not buried in a book or jumping out of an airplane, he works as an IT consultant.
John lives with his wife and two children in Pittsburgh, PA and is currently obsessing about the Internet of Things.
Preface
Creating PHP applications that respond quickly, avoid unnecessary page reloads, and provide great user interfaces, often requires complex JavaScript techniques. Even then, if you get that far, the results might not work across different browsers! With jQuery, you can use one of the most popular JavaScript libraries, forget about cross-browser issues, and simplify the creation of very powerful and responsive interfaces—all with the minimum of code.
This is the first book in the market that will ease the server-side PHP coder into the client-side world of the popular jQuery JavaScript library.
This book will show you how to use jQuery to enhance your PHP applications, with many examples using jQuery's user interface library jQuery UI, and other examples using popular jQuery plugins. It will help you to add exciting user interface features to liven up your PHP applications without having to become a master of client-side JavaScript.
This book will teach you how to use jQuery to create some really stunning effects, but without you needing to have in-depth knowledge of how jQuery works. It provides you with everything you need to build practical user interfaces, for everything from graphics manipulation and drag-and-drop to data searching, and much more. The book also provides practical demonstrations of PHP and jQuery and explains these examples, rather than starting from how JavaScript works and how it is different from PHP.
By the end of this book, you should be able to take any PHP application you have written, and transform it into a responsive, user-friendly interface, with capabilities you would not have dreamed of being able to achieve, all in just a few lines of JavaScript.
What this book covers
Chapter 1, Introduction and Overview, introduces you to what jQuery is, why you would want to use it, and why is it useful to combine it with PHP. Also, it gives a list of projects illustrating uses for combining PHP and jQuery.
Chapter 2, Quick Tricks, looks at a few quick examples on how to interface PHP and jQuery and a few tricks, which demonstrate how to relieve the most obvious resource wastes on the server.
Chapter 3, Tabs and Accordions, walks through the creation of tabs and accordions using the jQuery UI project, managing tabs and accordions using a rich text editor and a bit of PHP, and using Ajax to populate your accordion and tab panels.
Chapter 4, Forms and Form Validation, explores form validation using jQuery and PHP and how to use the same PHP configuration to validate on both sides—the server and the client side. It also covers examples on optimization of large select boxes and building auto-suggest fields.
Chapter 5, File Management, teaches you to manage almost everything—creating, uploading, editing, moving, downloading, and deleting files and directories.
Chapter 6, Calendars, builds a weekly calendar for you, which has events that can be created, edited, moved around, and deleted. It also takes care of recurring events.
Chapter 7, Image Manipulation, discusses methods for manipulating images with jQuery and PHP, along with some ways to make the changes non-destructive, so that multiple manipulations, such as select, rotate, resize, and crop, can be made on the same image.
Chapter 8, Drag and Drop, demonstrates a few uses of drag and drop, including sorting lists, dragging between lists, and hierarchical sorting, which can be used to improve the usability of your content management system.
Chapter 9, Data Tables, builds a very large data table and discusses how to navigate, sort, search, paginate, and search it using jQuery and Ajax.
Chapter 10, Optimization, shows the ways to optimize jQuery and various other elements of the web development environment.
What you need for this book
To try out the examples in this book, all you need is a test server; we recommend using PHP 5.2 or up. You will also need to download the jQuery library from http://docs.jquery.com/Downloading_jQuery.
Who this book is for
This book is for PHP application developers who want to improve their user interfaces through jQuery's capabilities and responsiveness. Whether you are familiar with jQuery or have only dabbled a little with JavaScript, this book will provide you with numerous practical examples on how to improve your application.
Conventions
In this book, you will find a number of styles of text that distinguish between different kinds of information. Here are some examples of these styles, and an explanation of their meaning.
Code words in text are shown as follows: The URL string we're working with includes a number of sSearch parameters.
A block of code is set as follows:
$dir='.'; // directory containing the scripts
$d=0;
foreach (new DirectoryIterator($dir) as $file) {
$d+=$file->getMTime();
}
?>
When we wish to draw your attention to a particular part of a code block, the relevant lines or items are set in bold:
$.getJSON('./calendar.php?action=get_event&id='+calEvent.id,function(eventdata){
var controls='javascript:calendar_delete_entry('+eventdata.id+');>'+'[delete]';
if(+eventdata.recurring)controls+='
'+'javascript:calendar_delete_recurrences('+eventdata.id+')>'+' [stop recurring]';
$('
Any command-line input or output is written as follows:
yum install php-pecl-imagick
New terms and important words are shown in bold. Words that you see on the screen, in menus or dialog boxes for example, appear in the text like this: When you click on this ? icon, smaller help icons will be shown next to all the elements in the page.
Note
Warnings or important notes appear in a box like this.
Tip
Tips and tricks appear like this.
Reader feedback
Feedback from our readers is always welcome. Let us know what you think about this book—what you liked or may have disliked. Reader feedback is important for us to develop titles that you really get the most out of.
To send us general feedback, simply send an email to <feedback@packtpub.com>, and mention the book title via the subject of your message.
If there is a book that you need and would like to see us publish, please send us a note in the SUGGEST A TITLE form on www.packtpub.com or email
If there is a topic that you have expertise in and you are interested in either writing or contributing to a book, see our author guide on www.packtpub.com/authors.
Customer support
Now that you are the proud owner of a Packt book, we have a number of things to help you to get the most from your purchase.
Tip
Downloading the example code for the book
Visit http://www.packtpub.com/files/code/6989_Code.zip to directly download the example code.
Errata
Although we have taken every care to ensure the accuracy of our content, mistakes do happen. If you find a mistake in one of our books—maybe a mistake in the text or the code—we would be grateful if you would report this to us. By doing so, you can save other readers from frustration, and help us to improve subsequent versions of this book. If you find any errata, please report them by visiting http://www.packtpub.com/support, selecting your book, clicking on the let us know link, and entering the details of your errata. Once your errata are verified, your submission will be accepted and the errata added to any list of existing errata. Any existing errata can be viewed by selecting your title from http://www.packtpub.com/support.
Piracy
Piracy of copyright material on the Internet is an ongoing problem across all media. At Packt, we take the protection of our copyright and licenses very seriously. If you come across any illegal copies of our works, in any form, on the Internet, please provide us with the location address or web site name immediately so that we can pursue a remedy.
Please contact us at <copyright@packtpub.com> with a link to the suspected pirated material.
We appreciate your help in protecting our authors, and our ability to bring you valuable content.
Questions
You can contact us at <questions@packtpub.com> if you are having a problem with any aspect of the book, and we will do our best to address it.
Chapter 1. Introduction and Overview
Welcome!
This book is a general overview of how to take advantage of jQuery's ease-of-use to make your PHP applications more snappy
on the client side.
The book is aimed at the PHP developers who usually don't write client-side JavaScript, and would like an example-based introduction demonstrating a wide variety of integrations between server-side and client-side code.
For years, JavaScript (the language that jQuery is written in) has been seen as a